package gek.uni.aspirant.ocl.rcp.command.handlers;

import gek.uni.aspirant.ocl.prolog.generator.generator.PrologGenerator;
import gek.uni.aspirant.uml.utils.UmlUtils;

import java.util.Collection;
import java.util.Iterator;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.uml2.uml.Model;
import org.eclipse.uml2.uml.UMLPackage;

public class BuidGeneralizationTree extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

		// Получаем ресурс uml-модели.
		// pathName - полный путь к файлу *.uml
		
		String pathName = "C:\\Eclipse_All\\Test.uml";
		URI uri = URI.createFileURI(pathName);
		Resource resource = UmlUtils.loadResource(uri);
		Collection<Model> models = EcoreUtil.getObjectsByType(resource
				.getContents(), UMLPackage.Literals.MODEL);
		Iterator<Model> modelsIter = models.iterator();
		Model umlModel = null;
		if (modelsIter.hasNext())
			umlModel = modelsIter.next();
		PrologGenerator prolGen = new PrologGenerator(umlModel);
		for (String l : prolGen.generateGeneralizationTreeFacts())
			System.out.println(l);
		return null;
	}

}
